package bean;

import java.math.BigDecimal;
import java.util.List;

public class Cart {
    private Integer totalCount;
    private BigDecimal totalPrice;
    private List<CartItem> items;

    public Cart() {
    }


    public void setItems(List<CartItem> items) {
        this.items = items;

        totalPrice = new BigDecimal("0");
        for (CartItem item : items) {
            totalPrice = totalPrice.add(item.getTotalPrice());
        }

        totalCount = items.size();
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public List<CartItem> getItems() {
        return items;
    }

    @Override
    public String toString() {
        return "Cart{" +
                "totalCount=" + totalCount +
                ", totalPrice=" + totalPrice +
                ", items=" + items +
                '}';
    }
}
